#实时监测页面
#站点统计页面
from selenium.webdriver.common.by import By
from base.base import Base

import time
import json
import re
with open(r'data\json_data\Statistics.json','r',encoding='utf-8') as f:
    data = json.load(f)['page']
class PageMonitor(Base):
    monitortitle_locator = (By.XPATH,'(//li[@role="menuitem"])[3]')
    #站点查询框
    input_site_locator = (By.CLASS_NAME,'ant-select-selection-search-input')
    #下拉框第一个元素
    seleted_locator = (By.XPATH,'(//div[@class="ant-cascader-menus"]//li)[1]')
    #设备查询框
    input_device_locator = (By.XPATH,'//span[contains(@class,"ant-input-affix-wrapper")]/input')
    #搜索数据
    seleted_info = (By.CLASS_NAME,'ant-empty-description')
    device_locator = (By.CLASS_NAME,'custom-tree-node')
    #设备名称
    device_headtitle_locator = (By.XPATH,'(//div[contains(@class,"ant-card")])[6]')
    #设备运行状态
    device_sate_locator = (By.XPATH,'(//div[@class="ant-card-body"])[4]')
    #测点
    testbit_locator = (By.CLASS_NAME,'monitor-value-con')
    #告警列表
    alart_list_locator = (By.CLASS_NAME,'ant-table-tbody')
    #页面跳转
    def page_jump(self):
        self.click(self.monitortitle_locator)
    #站点查询
    def input_site(self,name):
        self.clear(self.input_site_locator)
        self.input(self.input_site_locator,name)
        self.click(self.seleted_locator)
    #设备查询
    def input_device(self,name):
        self.clear(self.input_device_locator)
        self.input(self.input_device_locator,name)
    def get_info(self):
        return self.find(self.seleted_info).text
    def click_device(self):
        self.click(self.device_locator)
    def get_headtitle(self):
        return self.find(self.device_headtitle_locator).text
    #设备报警状态
    def get_devicesate(self):
        time.sleep(0.5)
        return self.find(self.device_sate_locator).text.split('\n')
    def get_testbit(self):
        return self.find(self.testbit_locator).text.replace('(℃)','').replace('(%)','').split('\n')
    def get_alartlist(self):
        # return self.find(self.alart_list_locator).text.replace('\n',' ').split(' ')
        return re.sub(r'\s(?!℃)', '&',self.find(self.alart_list_locator).text).split('&')